package com.air.common.util;

import java.util.ArrayList;
import java.util.List;

public class QueryCondition {
	
	private List<QueryExpression> list = new ArrayList<QueryExpression>();
	private List<OrderExpression> orderList = new ArrayList<OrderExpression>();
	
	
	//private String orderProperty = null;
	//private String orderDirection= QueryCondition._order_direction_desc;
	
	//public  static final String _order_direction_desc="DESC";
	//public  static final String _order_direction_asc="";
	
	
	public void setOrderList(List<OrderExpression> orderList)
    {
        this.orderList = orderList;
    }

    public List<OrderExpression> getOrderList()
    {
        return orderList;
    }
	
	/*public String getOrderProperty() {
		return orderProperty;
	}
	
	public String getOrderColumn(){
		return CamelFormatUtil.reverseCamel(orderProperty);
	}
	
	public String getOrderDirection() {
		return orderDirection;
	}*/

	public List<QueryExpression> getList() {
		return list;
	}

	public void addQueryCondition(String propertyName, Integer propertyValue,String operator) {
		this.addQueryCondition(propertyName, propertyValue+"", operator);
	}
	public void addQueryCondition(String propertyName, Long propertyValue,String operator) {
		this.addQueryCondition(propertyName, propertyValue+"", operator);
	}
	
	public void addQueryCondition(String propertyName, String propertyValue,String operator) {
	    QueryExpression queryExpression = new QueryExpression();
	    queryExpression.setPropertyName(propertyName);
	    queryExpression.setPropertyValue(propertyValue);
	    queryExpression.setOperator(operator);
	    list.add(queryExpression);
	}
	
	
	
	public void addQueryCondition(String propertyName, List<?> propertyValueList,String operator) {
		 QueryExpression queryExpression = new QueryExpression();
		 queryExpression.setPropertyName(propertyName);
		 queryExpression.setPropertyValueList(propertyValueList);
		 queryExpression.setOperator(operator);
		 list.add(queryExpression);
	}
	
	public void addQueryCondition(QueryExpression queryExpression){
	    list.add(queryExpression);
	}
	public void addQueryCondition(List<QueryExpression> queryExpressions){
	    for(QueryExpression queryExpression:queryExpressions){
	        addQueryCondition(queryExpression);
	    }
	}
	
	public void addManualCondition(String condition){
	    QueryExpression queryExpression = new QueryExpression();
	    queryExpression.setOperator(QueryExpression.MANUAL);
	    queryExpression.setManualString("("+condition+")");
	    list.add(queryExpression);
	}
	
	
	
	public void addOrderExpression(String propertyName,String direction){
	    OrderExpression  orderExpression= new OrderExpression();
	    orderExpression.setPropertyName(propertyName);
	    orderExpression.setOrderDirection(direction);
	    orderList.add(orderExpression);
	}
	
	
	
	
	public void cleanQueryCondition(){
	    this.list = new ArrayList<QueryExpression>(); 
	    this.orderList = new ArrayList<OrderExpression>();
	}

    
	
}	
